/**
 * 历史记录类型
 * 用于告知解析器如何返回上一个命令
 * @enum {string}
 */
export const HistoryType = {
  None: "None",
  // 打开文件夹
  OpenFolder: "OpenFolder",
  // 检索内容
  SearchContent: "SearchContent",
  BackUp: "BackUp"
};

/**
 * 声明一个要素库项，与后端做映射
 */
class LibraryItem {
  /**
   * 项Id
   * @type {string}
   */
  id;
  /**
   * 要素库显示名称
   * @type {string}
   */
  name;
  /**
   * 知识项类型
   * @type {LibraryType}
   */
  libraryType;
  folderCode;
  /**
   * 要素库参数
   * @type {{[key:string]:any}}
   */
  param;
  /**
   * 孩子
   * @type {Array<LibraryItem>}
   */
  children;
  /**
   * 缩略图
   * @type {string}
   */
  thumbnail = "";
  /**
   * 是否为系统创建的
   * @type {boolean}
   */
  system;

  /**
   * 父项
   */
  parent;

  constructor(param) {
    if (!param) {
      return;
    }
    this.id = param.id;
    this.libraryType = param.elementLibraryType;
    this.name = param.name;
    this.folderCode = param.folderCode;
    this.param = param.param;
    this.children = [];
    this.thumbnail = param?.thumbnail ?? "";
    this.system = param.system;
  }

  setThumbnail(thumbnail) {
    this.thumbnail = thumbnail;
  }
}

class LibraryResultItem extends LibraryItem {
  /**
   * @type {string} 文件路径
   */
  path;

  constructor(param, path) {
    super(param);
    this.path = path;
  }
}

/**
 *  要素库类型
 * @enum {{FOLDER: string, MODEL: string}}
 */
const LibraryType = {
  FOLDER: "FOLDER", // 文件夹
  MODEL: "MODEL", // 模型
  SKETCH: "SKETCH",//草图
}

class HistoryRecord {
  /**
   * @type {HistoryType}
   */
  type;
  /**
   * @type {string} // 参数
   */
  param;
}

const LibraryModelType = {
  Part: "Part",
  Assembly: "Assembly"
}

export { HistoryRecord, LibraryType, LibraryItem, LibraryResultItem, LibraryModelType };